#Anaconda/envs/pyqtenv python
# -*- coding: utf-8 -*-
'''
@File    :   AppWebspider.py
@Time    :   2024/10/18 16:08:30
@Author  :   WangXi 
@Version :   1.0
@Desc    :   Built in PyQt5
             WebSpider Gui主界面逻辑控制
             主界面设计文件为 App_Webspider.ui->Ui_App_Webspider.py
'''

from PyQt5.QtWidgets import QMainWindow, QDesktopWidget
from PyQt5.QtCore import pyqtSlot

from Netterminal.Forms.Ui_App_Webspider import Ui_MainWindow_webspider
from Netterminal.Sources.Device.DevWebController.DevWebController import DevWebController


class AppWebspider(QMainWindow, Ui_MainWindow_webspider):
    def __init__(self, parent=None):
        super(AppWebspider, self).__init__(parent)
        self.setupUi(self)
        
        screen = QDesktopWidget().screenGeometry()
        screenWidth = screen.width()
        screenHeight = screen.height()
        self.resize(int(screenWidth * 0.6), int(screenHeight * 0.9))
        
        self.initComponent()
        
        self.ready()

    def initComponent(self):
        self.dev_web = DevWebController(name="WebSpider",
                                        **{"tb_showinfo": self.tb_showinfo})

    def ready(self):
        self.dev_web.ready()
        self.pb_start.clicked.connect(self.start_spider)

    @pyqtSlot()
    def start_spider(self):
        self.dev_web.start(search_text=self.le_input.text())
